package com.cndw.kungfu.socket;

import java.util.Map;

import com.cndw.commons.util.BlankUtils;

/**
 * 响应对象
 * 
 * 
 * @author <a href="mailto:whz-work@163.com">汪洪州</a>
 * 
 * @since 1.0 Create on 2011-5-18
 */
public class SocketResponse {

	/**
	 * 返回消息状态(成功为0,失败为1)
	 */
	private int r;

	/**
	 * 返回消息的时间戳
	 */
	private long t;

	/**
	 * 返回的消息提
	 */
	private Object m;

	private Object b;

	/**
	 * 模块
	 */
	private String module;

	/**
	 * 事件
	 */
	private String action;

	/**
	 * 请求序列号
	 */
	private String requestId;

	/**
	 * 是否已经响应完成
	 */
	private boolean responsed = false;

	public boolean isResponsed() {
		return responsed;
	}

	public void setResponsed(boolean responsed) {
		this.responsed = responsed;
	}

	public int getR() {
		return r;
	}

	public void setR(int r) {
		this.r = r;
	}

	public String getModule() {
		return module;
	}

	public void setModule(String module) {
		this.module = module;
	}

	public String getAction() {
		return action;
	}

	public void setAction(String action) {
		this.action = action;
	}

	public String getRequestId() {
		return requestId;
	}

	public void setRequestId(String requestId) {
		this.requestId = requestId;
	}

	public Object getM() {
		return m;
	}

	public void setM(Object m) {
		this.m = m;
	}

	public long getT() {
		return t;
	}

	public void setT(long t) {
		this.t = t;
	}

	public Object getB() {
		return b;
	}

	public void setB(Object b) {
		this.b = b;
	}

	@SuppressWarnings("unchecked")
	public String getMessage() {
		if (!BlankUtils.isBlank(b)) {
			if (Map.class.isAssignableFrom(b.getClass())) {
				Map<String, Object> map = (Map<String, Object>) b;
				return String.valueOf(map.get("message"));
			}
		}
		return null;
	}

	@Override
	public String toString() {
		return "SocketResponse [r=" + r + ", t=" + t + ", m=" + m +", b=" + b + ", module=" + module + ", action=" + action + ", requestId=" + requestId + ", responsed=" + responsed + "]";
	}

}
